package com.ruoyi.web.controller.owner;

import java.util.List;

import com.ruoyi.common.config.HeadNum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.util.GetSessionValueUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.owner.domain.FzBuildingOwner;
import com.ruoyi.owner.service.IFzBuildingOwnerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业主成员Controller
 * 
 * @author ruoyi
 * @date 2020-03-09
 */
@Controller
@RequestMapping("/owner/owner")
public class FzBuildingOwnerController extends BaseController
{
    private String prefix = "owner/owner";

    @Autowired
    private IFzBuildingOwnerService fzBuildingOwnerService;

    @RequiresPermissions("owner:owner:view")
    @GetMapping()
    public String owner()
    {
        return prefix + "/owner";
    }

    /**
     * 查询业主成员列表
     */
    @RequiresPermissions("owner:owner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FzBuildingOwner fzBuildingOwner)
    {
        startPage();
        List<FzBuildingOwner> list = fzBuildingOwnerService.selectFzBuildingOwnerList(fzBuildingOwner);
        return getDataTable(list);
    }

    /**
     * 导出业主成员列表
     */
    @RequiresPermissions("owner:owner:export")
    @Log(title = "业主成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzBuildingOwner fzBuildingOwner)
    {
        List<FzBuildingOwner> list = fzBuildingOwnerService.selectFzBuildingOwnerList(fzBuildingOwner);
        ExcelUtil<FzBuildingOwner> util = new ExcelUtil<FzBuildingOwner>(FzBuildingOwner.class);
        return util.exportExcel(list, "owner");
    }

    /**
     * 新增业主成员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存业主成员
     */
    @RequiresPermissions("owner:owner:add")
    @Log(title = "业主成员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzBuildingOwner fzBuildingOwner)
    {
        fzBuildingOwner.setMemberId(HeadNum.MEMBER_HEAD+ DateUtils.getTimeMillis());
            fzBuildingOwner.setcId(GetSessionValueUtil.getCommunity());
        fzBuildingOwner.setCreateName(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzBuildingOwnerService.insertFzBuildingOwner(fzBuildingOwner));
    }

    /**
     * 修改业主成员
     */
    @GetMapping("/edit/{memberId}")
    public String edit(@PathVariable("memberId") String memberId, ModelMap mmap)
    {
        FzBuildingOwner fzBuildingOwner = fzBuildingOwnerService.selectFzBuildingOwnerById(memberId);
        mmap.put("fzBuildingOwner", fzBuildingOwner);
        return prefix + "/edit";
    }

    /**
     * 修改保存业主成员
     */
    @RequiresPermissions("owner:owner:edit")
    @Log(title = "业主成员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzBuildingOwner fzBuildingOwner)
    {
        fzBuildingOwner.setUpdateName(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzBuildingOwnerService.updateFzBuildingOwner(fzBuildingOwner));
    }

    /**
     * 删除业主成员
     */
    @RequiresPermissions("owner:owner:remove")
    @Log(title = "业主成员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzBuildingOwnerService.deleteFzBuildingOwnerByIds(ids));
    }
}
